package ius.mantianx.config;

import ius.mantianx.handler.ThyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author starrysky
 * @title: ThyMvcConfig
 * @projectName rev_thymeleaf_boot
 * @description: configuration layer
 * @date 2021/2/808:32
 */
@Configuration
public class ThyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/main.html").setViewName("dashboard");
    }
    @Bean
    public LocaleResolver localeResolver(){
        return new ThyLocalResolver();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ThyInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/css/**","/js/**","/img/**","/","/login","/login.html","/user/login");
    }
}
